package interfaces;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.animation.FadeTransition;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
 * Profile Controller.
 */
public class MenuPrincipalController extends AnchorPane implements Initializable {

	
	@FXML
    private Button emitirlicencia;
    @FXML
    public VBox vbox;
    @FXML
    private MenuItem menuitememitirlicencia;
    @FXML
    private MenuItem menulogin;
    @FXML
    private MenuItem menutitular;
    @FXML
    private MenuItem menulicencia;
    @FXML
    private MenuItem menusalir;
    @FXML
    private MenuItem menuitemaltatitular;
    @FXML
    private MenuItem menuLogout;
    @FXML
    private MenuItem menuitemacercade;
    @FXML
    private MenuItem imprimirlicencia;
    @FXML
    AnchorPane profile;
    private Main application;
    
    public void setApp(Main application){
        this.application = application;
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
    	
    	menulogin.setDisable(true);
    	
    	menusalir.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	        application.gotoSalir();
    	    }
    	});
    	
    	menuitememitirlicencia.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	        application.emitirlicencia();
    	    }
    	});
    	
    	menuitemaltatitular.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	        application.gotoAltaTitular();
    	    }
    	});
    	
    	menuitemacercade.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	        application.gotoAcercaDe();
    	    }
    	});   
    	 menuLogout.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	        application.gotologout();
    	    }
    	});   
    	 
    	 imprimirlicencia.setOnAction(new EventHandler<ActionEvent>() {
    	    @Override public void handle(ActionEvent e) {
    	       application.gotoImprimirLicencia();
    	    }
    	});   
    }
    
    public void volver(ActionEvent event) {
    
    	 try {
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	application.userLogout();
    }
    
    public void emitirlicencia(ActionEvent event) {
    	
    	
        application.emitirlicencia();
    }
    
    private FadeTransition fadeOut(final Duration duration, final Node node) {
        final FadeTransition fadeOut = new FadeTransition(duration,node);
        fadeOut.setFromValue(1);
        fadeOut.setToValue(0);
        fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                node.setVisible(false);
            }
        });
        return fadeOut;
    }
    
    public void processLogout(ActionEvent event) {
        if (application == null){
            // We are running in isolated FXML, possibly in Scene Builder.
            // NO-OP.
            return;
        }
        
        application.userLogout();
    }
    
    public void salir(ActionEvent event){
    	application.stage.close();
        }
    
    public void altatitular(ActionEvent event){
    	application.gotoAltaTitular();
    	
    }
}
